package com.boarsoft.boar.sequence.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boarsoft.bean.ReplyInfo;
import com.boarsoft.boar.common.Constants;
import com.boarsoft.boar.sequence.biz.SequenceSegmentBiz;
import com.boarsoft.boar.sequence.entity.SequenceSegment;
import com.boarsoft.common.Authorized;
import com.boarsoft.common.Util;
import com.boarsoft.common.dao.PagedResult;
import com.boarsoft.common.util.JsonUtil;

/**
 * 提供对号段的查询和人工干预手段
 * 
 * @author Mac_J
 *
 */
@RestController
@RequestMapping("/segment")
public class SequenceSegmentAction {

	@Autowired
	private SequenceSegmentBiz sequenceSegmentBiz;

	@RequestMapping("/save")
	@Authorized(code = "sequence.segment.save")
	public ReplyInfo<Object> save(SequenceSegment o) {
		sequenceSegmentBiz.save(o);
		return ReplyInfo.SUCCESS;
	}

	@RequestMapping("/update")
	@Authorized(code = "sequence.segment.update")
	public ReplyInfo<Object> update(SequenceSegment o) {
		sequenceSegmentBiz.save(o);
		return ReplyInfo.SUCCESS;
	}

	@RequestMapping("/delete")
	@Authorized(code = "sequence.segment.delete")
	public ReplyInfo<Object> delete(String id) {
		if (Util.strIsEmpty(id)) {
			return new ReplyInfo<Object>(Constants.WARN_INVALID, "delete");
		}
		sequenceSegmentBiz.delete(id);
		return ReplyInfo.SUCCESS;
	}

	@RequestMapping("/list")
	@Authorized(code = "sequence.segment.list")
	public ReplyInfo<Object> list(String sequenceId, String orderBy, int pageNo, int pageSize) {
		PagedResult<SequenceSegment> pr = sequenceSegmentBiz.list(sequenceId, orderBy, pageNo, pageSize);
		return new ReplyInfo<Object>(true, JsonUtil.from(pr));
	}

	public SequenceSegmentBiz getSequenceSegmentBiz() {
		return sequenceSegmentBiz;
	}

	public void setSequenceSegmentBiz(SequenceSegmentBiz sequenceSegmentBiz) {
		this.sequenceSegmentBiz = sequenceSegmentBiz;
	}
}